package com.bandapp.ui;

import java.net.MalformedURLException;
import java.util.ArrayList;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;

import com.bandapp.adapters.BandAdapter;
import com.bandapp.bo.Band;

public class Main extends ListActivity {
	
	
	public static ArrayList<Band> bands;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
      
        try {

            /*
             * make dummy bands
             */
            bands = new ArrayList<Band>();
            Band amatorski = new Band("Amatorski");
			amatorski.setBandFeed("http://twitter.com/statuses/user_timeline/56048825.rss");
			amatorski.setImageForFeed("amatorski.jpg");
			bands.add(amatorski);
		    
			Band soad = new Band("Serj Tankian");
			soad.setBandFeed("http://twitter.com/statuses/user_timeline/19721402.rss");
			soad.setImageForFeed("serj_tankian.jpg");
			bands.add(soad);
			
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
       
        
        /*
         * make a BandAdapter which acts as a model and View for the ListView
         * note that the layout can be ( and should be ) customized with an customized xml file
         */
        BandAdapter<Band> adapter = new BandAdapter<Band>(this,android.R.layout.simple_list_item_1,bands);
        setListAdapter(adapter);
        
    }
    
    protected void onListItemClick(ListView l, View v, int position, long id){
    	/*
    	 * We pass the position of the invoked click to the Intent , so that the tabactivity can retrieve it, 
    	 * and get the band out of the bands collection which is static.
    	 */
    	 Intent intent = new Intent(Main.this, BandActivity.class);
    	 intent.putExtra("position", position);    	
         startActivity(intent);        	
    }
    
    
}